package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"learningProject/mytest/pb"
	"net"
)

// 定义类
type Children struct {
}

// 按接口绑定类方法,是pb文件里的interface
func (c *Children) SayHello(ctx context.Context, t *pb.Teacher) (*pb.Teacher, error) {
	t.Name += "say hello"
	return t, nil
}
func main() {
	// 初始化一个grpc对象
	grpcServer := grpc.NewServer()

	// 注册服务
	pb.RegisterSayNameServer(grpcServer, &Children{})

	// 设置监听，指定ip和端口
	listener, err := net.Listen("tcp", "127.0.0.1:8800")
	if err != nil {
		fmt.Println("listen err:", err)
	}
	defer listener.Close()

	// 启动服务
	grpcServer.Serve(listener)
}
